home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-04 | 3.1 KB | 93 lines | [TEXT/MMCC] |
- /**************************************************************************
- LGBControl
-
- Public domain, by Zig Zichterman.
-
- Just a few utilities that the control classes use.
-
- Some of the drawing code is taken from the public domain source
- accompanying _develop_ 15.
- **************************************************************************/
- #include "LGBControl.h"
-
- const LGBControl_boxWidth = 12; // width of checkboxes, radio buttons
-
- //—————————————————————————————————————————————————————————————————————————
- // Drawing Utilities
- //—————————————————————————————————————————————————————————————————————————
-
- /**************************************************************************
- CountLines() [static]
-
- Count the number of carriage return ('\r') characters in the
- given string.
-
- carriage return is NEVER part of a 2-byte character, so this will
- work with double byte scripts, too.
- **************************************************************************/
- short
- LGBControl::CountLines(const StringPtr inString)
- {
- short numLines = 1; // always have at least 1 line
- short charsRemaining = *inString;
- unsigned char *p = inString + 1;
- for (;charsRemaining--;p++) {
- if (*p == '\r') numLines++;
- }
- return numLines;
- }
-
- /**************************************************************************
- TitleHeight() [static]
-
- Return the height of the title in pixels. The font must already be
- set up.
- **************************************************************************/
- short
- LGBControl::TitleHeight(const StringPtr inTitle)
- {
- FontInfo info;
- ::GetFontInfo(&info);
- const short lineHeight = info.ascent + info.descent + info.leading;
- const short numLines = CountLines(inTitle);
- return lineHeight * numLines;
- }
-
- /**************************************************************************
- CalcBoxes() [static]
-
- Calculate the boxes for the checkbox/radio button and its title
- **************************************************************************/
- void
- LGBControl::CalcBoxes(const Rect &inControlRect, const StringPtr inTitle,
- Rect &outCheckbox, Rect &outTitleBox)
- {
- short centerV = (inControlRect.top + inControlRect.bottom)/2;
- Boolean ltor = (GetSysJust() == 0);
-
- // checkbox is v-centered, 14-px tall
- outCheckbox.top = centerV - (LGBControl_boxWidth/2);
- outCheckbox.bottom = outCheckbox.top + LGBControl_boxWidth;
- // checkbox is left- or right-aligned, offset by a couple pix
- if (ltor) {
- outCheckbox.left = inControlRect.left + 2;
- outCheckbox.right = outCheckbox.left + LGBControl_boxWidth;
- } else {
- outCheckbox.right = inControlRect.right - 2;
- outCheckbox.left = outCheckbox.right - LGBControl_boxWidth;
- }
-
- // textbox is v-centered, tall enough for all lines
- const short titleHeight = LGBControl::TitleHeight(inTitle);
- outTitleBox.top = centerV - (titleHeight/2);
- outTitleBox.bottom = outTitleBox.top + titleHeight;
- // textbox is next to the checkbox
- if (ltor) {
- outTitleBox.left = outCheckbox.right + 3;
- outTitleBox.right = inControlRect.right;
- } else {
- outTitleBox.right = outCheckbox.left - 3;
- outTitleBox.left = inControlRect.left;
- }
- }
-